<template>
  <div>
    <el-dialog v-model="dialogEditVisibel" title="编辑">
      <el-form
        ref="ruleFormRef"
        :model="form"
        label-width="150"
        style="padding: 0px 15px"
        :rules="rule"
        status-icon
        dis
      >
        <el-form-item
          :label="name.enterpriseCode"
          :label-width="formLabelWidth"
          prop="enterpriseCode"
        >
          <el-input
            disabled
            clearable
            placeholder="请输入数据"
            v-model="form.enterpriseCode"
          />
        </el-form-item>
        <el-form-item
          :label="name.dataCode"
          :label-width="formLabelWidth"
          prop="dataCode"
        >
          <el-input
            clearable
            placeholder="请输入数据"
            v-model="form.dataCode"
          />
        </el-form-item>
        <el-form-item
          :label="name.dataValue"
          :label-width="formLabelWidth"
          prop="dataValue"
        >
          <el-input
            clearable
            placeholder="请输入数据"
            v-model="form.dataValue"
          />
        </el-form-item>
        <el-form-item
          :label="name.dataValueUnit"
          :label-width="formLabelWidth"
          prop="dataValueUnit"
        >
          <el-input
            clearable
            placeholder="请输入数据"
            v-model="form.dataValueUnit"
          />
        </el-form-item>
        <el-form-item
          :label="name.convertRation"
          :label-width="formLabelWidth"
          prop="convertRation"
        >
          <el-input
            clearable
            placeholder="请输入数据"
            v-model="form.convertRation"
          />
        </el-form-item>
        <el-form-item
          :label="name.convertRationUnit"
          :label-width="formLabelWidth"
          prop="convertRationUnit"
        >
          <el-input
            clearable
            placeholder="请输入数据"
            v-model="form.convertRationUnit"
          />
        </el-form-item>
        <el-form-item
          :label="name.dataIndex"
          :label-width="formLabelWidth"
          prop="dataIndex"
        >
          <el-input
            disabled
            clearable
            placeholder="请输入数据"
            v-model="form.dataIndex"
          />
        </el-form-item>
        <el-form-item
          :label="name.inputType"
          :label-width="formLabelWidth"
          prop="inputType"
        >
          <el-input
            clearable
            placeholder="请输入数据"
            v-model="form.inputType"
          />
        </el-form-item>
        <el-form-item
          :label="name.scope"
          :label-width="formLabelWidth"
          prop="scope"
        >
          <el-input clearable placeholder="请输入数据" v-model="form.scope" />
        </el-form-item>
        <el-form-item
          :label="name.statDate"
          :label-width="formLabelWidth"
          prop="statDate"
        >
          <el-input
            disabled
            clearable
            placeholder="请输入数据"
            v-model="form.statDate"
          />
        </el-form-item>

        <el-form-item
          :label="name.statType"
          :label-width="formLabelWidth"
          prop="statType"
        >
          <el-input
            disabled
            clearable
            placeholder="请输入数据"
            v-model="form.statType"
          />
        </el-form-item>
        <el-form-item
          :label="name.uploadDate"
          :label-width="formLabelWidth"
          prop="uploadDate"
        >
          <el-input
            disabled
            clearable
            placeholder="请输入数据"
            v-model="form.uploadDate"
          />
        </el-form-item>
        <el-form-item>
          <div>
            <el-button @click="dialogEditVisibel = false" type="info"
              >取消</el-button
            >
            <el-button type="primary" @click="submitForm(ruleFormRef)">
              确定
            </el-button>
          </div>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script setup>
import { reactive, ref } from "vue";
import mitts from "@/utils/bus.js";
import { update } from "@/api/enterprise";
import { ElMessage } from "element-plus";
let form = reactive({
  dataId: "",
  enterpriseCode: "",
  dataCode: "",
  dataValue: "",
  dataValueUnit: "",
  convertRation: "",
  convertRationUnit: "",
  valid: "",
  scope: "",
  inputType: "",
  statType: "",
  statDate: "",
  uploadDate: "",
  platformTime: "",
  remark: "",
  updateTime: "",
  regVersion: "",
  dicVersion: "",
  dataIndex: "",
  lastReportStatu: "",
  errorNums: "",
  opType: "",
  enterName: "",
});
const rule = {};
const dialogEditVisibel = ref(false);
const ruleFormRef = ref();
const name = reactive({
  enterpriseCode: "社会信用代码",
  dataCode: "数据项编码",
  dataValue: "上传数据",
  dataValueUnit: "上传数据单位",
  convertRation: "折标系数",
  convertRationUnit: "折标系数单位",
  dataIndex: "端系统记录索引",
  inputType: "数据采集类型",
  scope: "数据范围",
  statDate: "数据统计时间",
  statType: "数据采集频率",
  uploadDate: "数据上传时间",
});
const ruleNmae = reactive({
  enterpriseCode: "社会信用代码",
  dataCode: "数据项编码",
  dataValue: "上传数据",
  //dataValueUnit: "上传数据单位",
  convertRation: "折标系数",
  //convertRationUnit: "折标系数",
  //dataIndex: "端系统记录索引",
  inputType: "数据采集类型",
  scope: "数据范围",
  statDate: "数据统计时间",
  statType: "数据采集频率",
})

mitts.on("editDialog", (e) => {
  dialogEditVisibel.value = true;
  form = reactive(e);
  for (let key in ruleNmae) {
    let tempd = JSON.parse(
      '[{"required":true,"message":"请输入数据","trigger":"blur"}]'
    );
    rule[key] = tempd;
  }
});
const submitForm = async (formEl) => {
  await formEl.validate((valid, fields) => {
    if (valid) {
      //验证成功,开始进行数据的更新或者新增
      update(form).then((res)=>{
        if(res.status != 200){
          ElMessage.error("修改失败,请联系管理员!");
          return;
        }
        ElMessage.success("修改成功！");
        dialogEditVisibel.value = false;
        mitts.emit("editSuccess", true);
      }).catch((msg)=>{

      })
    } else {
      console.log("error submit!", fields);
    }
  });
};
</script>
<style lang="scss"></style>
